{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 8.3 Radix sort"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8.3-1\n",
    "\n",
    "> Using Figure 8.3 as a model, illustrate the operation of RADIX-SORT on the following list of English words: COW, DOG, SEA, RUG, ROW, MOB, BOX, TAB, BAR, EAR, TAR, DIG, BIG, TEA, NOW, FOX."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "| 0 |   1   |   2   |   3   |\n",
    "|:-:|:-----:|:-----:|:-----:|\n",
    "|COW|SE__A__|T__A__B|__B__AR|\n",
    "|DOG|TE__A__|B__A__R|__B__IG|\n",
    "|SEA|MO__B__|E__A__R|__B__OX|\n",
    "|RUG|TA__B__|T__A__R|__C__OW|\n",
    "|ROW|DO__G__|S__E__A|__D__IG|\n",
    "|MOB|RU__G__|T__E__A|__D__OG|\n",
    "|BOX|DI__G__|D__I__G|__E__AR|\n",
    "|TAB|BI__G__|B__I__G|__F__OX|\n",
    "|BAR|BA__R__|M__O__B|__M__OB|\n",
    "|EAR|EA__R__|D__O__G|__N__OW|\n",
    "|TAR|TA__R__|C__O__W|__R__OW|\n",
    "|DIG|CO__W__|R__O__W|__R__UG|\n",
    "|BIG|RO__W__|N__O__W|__S__EA|\n",
    "|TEA|NO__W__|B__O__X|__T__AB|\n",
    "|NOW|BO__X__|F__O__X|__T__AR|\n",
    "|FOX|FO__X__|R__U__G|__T__EA|"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8.3-2\n",
    "\n",
    "> Which of the following sorting algorithms are stable: insertion sort, merge sort, heapsort, and quicksort? Give a simple scheme that makes any sorting algorithm stable. How much additional time and space does your scheme entail?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Stable: insertion sort, merge sort.\n",
    "\n",
    "When two values are equals, compare the original index. Additional space: $\\Theta(n)$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8.3-3\n",
    "\n",
    "> Use induction to prove that radix sort works. Where does your proof need the assumption that the intermediate sort is stable?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\dots$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8.3-4\n",
    "\n",
    "> Show how to sort n integers in the range $0$ to $n^3 - 1$ in $O(n)$ time."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$n$-ary radix sort, including three $O(n)$ counting sort."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8.3-5 $\\star$\n",
    "\n",
    "> In the first card-sorting algorithm in this section, exactly how many sorting passes are needed to sort $d$-digit decimal numbers in the worst case? How many piles of cards would an operator need to keep track of in the worst case?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$\\Theta(k^d)$ passes.\n",
    "\n",
    "$\\Theta(nk)$ piles."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
